n=input()
n=n.split()
if len(n)!=3:
    print("Wrong input")
    exit(0)
a=n[0]
b=n[1]
c=n[2]
ch=0
k=0
t=0
min_ch=0
max_ch=0
first=100
second=10
third=1
def prost(sigma):
    if sigma % 2 == 0:
        return sigma == 2
    d = 3
    while d * d <= sigma and sigma % d != 0:
        d += 2
    return d * d > sigma
if len(n)!=3:
    print("Wrong input")
    exit(0)

if a=="zero":
    print("Wrong input")
    exit(0)
elif a=="one":
    ch+=first*1
elif a=="two":
    ch+=first*2
elif a=="three":
    ch+=first*3
elif a=="four":
    ch+=first*4
elif a=="five":
    ch+=first*5
elif a=="six":
    ch+=first*6
elif a=="seven":
    ch+=first*7
elif a=="eight":
    ch+=first*8
elif a=="nine":
    ch+=first*9
else:
    print("Wrong input")
    exit(0)
if b=="zero":
    ch+=0
elif b=="one":
    ch+=second*1
elif b=="two":
    ch+=second*2
elif b=="three":
    ch+=second*3
elif b=="four":
    ch+=second*4
elif b=="five":
    ch+=second*5
elif b=="six":
    ch+=second*6
elif b=="seven":
    ch+=second*7
elif b=="eight":
    ch+=second*8
elif b=="nine":
    ch+=second*9
else:
    print("Wrong input")
    exit(0)
if c=="zero":
    ch+=0
elif c=="one":
    ch+=1
elif c=="two":
    ch+=2
elif c=="three":
    ch+=3
elif c=="four":
    ch+=4
elif c=="five":
    ch+=5
elif c=="six":
    ch+=6
elif c=="seven":
    ch+=7
elif c=="eight":
    ch+=8
elif c=="nine":
    ch+=9
else:
    print("Wrong input")
    exit(0)
min_ch=ch
max_ch=ch
while k==0:
    if prost(min_ch)==True:
        k+=1
        break
    min_ch-=1
while t==0:   
    if prost(max_ch)==True:
        t+=1
        break
    max_ch+=1      
if (ch-min_ch)<(max_ch-ch):
    print(min_ch)
elif (ch-min_ch)>(max_ch-ch):
        print(max_ch)
elif (ch-min_ch)==(max_ch-ch):
    if max_ch==min_ch:
        print(ch)
    else:
        print(min_ch)